

* APPENDIX H - Randomness of Time of Survey-Taking


clear all	
cd "${data}"	
use cses_imd.dta, clear

rename IMD1006_NAM country
keep if country=="Australia" | country=="Austria" | country=="Belgium" | country=="Canada" | country=="Denmark" | country=="Finland" | country=="France" | country=="Germany" | country=="Greece" | country=="Iceland" | country=="Ireland" | country=="Italy" | country=="Japan" | country=="Netherlands" | country=="New Zealand" | country=="Norway" | country=="Portugal" | country=="Spain" | country=="Sweden" | country=="Switzerland" | country=="Great Britain" | country=="United States of America" 

gen election = IMD1004
drop if election=="DNK_2001" | election=="FIN_2003" | election=="FRA_2002" | election=="GRC_2012" | election=="ISL_2007" | election=="ITA_2006" | election=="JPN_2004" | election=="NOR_2001" | election=="PRT_2005"
 
drop if country=="Japan"

gen daysafter = IMD1014_1 if IMD1014_1<340

gen female =.
replace female = 1 if IMD2002==2
replace female = 0 if IMD2002==1

gen education = IMD2003 
replace education = . if education > 4 
label define education 0"no education" 1"primary or lower secondary" 2"higher secondary" 3"post-secondary" 4"university" 
label values education education


gen labourstatus = .
replace labourstatus = 1 if IMD2014==00 | IMD2014==01 | IMD2014==02 | IMD2014==03 
replace labourstatus = 2 if IMD2014==05
replace labourstatus = 4 if IMD2014==07
replace labourstatus = 3 if IMD2014==06
replace labourstatus = 5 if IMD2014==09
replace labourstatus = 6 if IMD2014==04 | IMD2014==08 | IMD2014==10 | IMD2014==11 | IMD2014==12
label define labourstatus 1"employed" 2"unemployed" 3"student" 4"retired" 5"permanently disabled" 6"other"
label values labourstatus labourstatus

replace IMD2007 = . if IMD2007>4
rename IMD2007 ruralurban
label define ruralurban 1"village" 2"small town" 3"suburbs of large city" 4"large city"
label values ruralurban ruralurban

gen age = IMD2001_1 if IMD2001_1<121   // continous

gen income = IMD2006
replace income = . if IMD2006>5
label define income 1"lowest quantile" 2"second quantile" 3"third quantile" 4"fourth quantile" 5"highest quantile"
label values income income

encode IMD1004, generate(IMD1004_)

* A2 running the models at the election level with election FEs.  

eststo bias1 : regress daysafter female i.IMD1004_, robust cluster(IMD1004_)
eststo bias2 : regress daysafter i.education i.IMD1004_, robust cluster(IMD1004_)
eststo bias3 : regress daysafter age i.IMD1004_, robust cluster(IMD1004_) 
eststo bias4 : regress daysafter i.labourstatus i.IMD1004_, robust cluster(IMD1004_) 
eststo bias5 : regress daysafter i.ruralurban i.IMD1004_, robust cluster(IMD1004_) 
eststo bias6 : regress daysafter i.income i.IMD1004_, robust cluster(IMD1004_) 

*save the estimates
cd "${tables}"	
esttab bias1 bias2 bias3 bias4 bias5 bias6 using bias.tex, replace b(3) se(3) r2  nogap


* A3 plotting the "NAME OF THE FIGURE" in the manuscript

coefplot bias1 bias2 bias3 bias4 bias5 bias6, drop(_cons *.IMD1004_) color(gs7%75) ciopts(color(gs7%75)) legend(off) xline(0, lpattern(solid) lcolor(black)) xtitle("days since election") level(95)


 graph save "${figures}/figureH1.gph",  replace
 graph export "${figures}/figureH1.png",  replace
 
 

 
 *****************************************************************************
 *****************************************************************************
 *****************************************************************************
 
 
 
clear all	
cd "${data}"	
use cses_imd.dta, clear


gen daysafter = IMD1014_1 if IMD1014_1<340


gen age = IMD2001_1 if IMD2001_1<121   // continous

 * SEX
 
gen female =.
replace female = 1 if IMD2002==2
replace female = 0 if IMD2002==1

 *EDUCATION
 
gen education = IMD2003 
replace education = . if education > 4 

*reference category is no education 
gen education1 = .
replace education1 = 1 if education==1
replace education1 = 0 if education==0

gen education2 = .
replace education2 = 1 if education==2
replace education2 = 0 if education==0

gen education3 = .
replace education3 = 1 if education==3
replace education3 = 0 if education==0

gen education4 = .
replace education4 = 1 if education==4
replace education4 = 0 if education==0


* LABOUR STATUS


gen labourstatus = .
replace labourstatus = 0 if IMD2014==00 | IMD2014==01 | IMD2014==02 | IMD2014==03 // 
replace labourstatus = 1 if IMD2014==05
replace labourstatus = 2 if IMD2014==07
replace labourstatus = 3 if IMD2014==06
replace labourstatus = 4 if IMD2014==09
replace labourstatus = 5 if IMD2014==04 | IMD2014==08 | IMD2014==10 | IMD2014==11 | IMD2014==12

*reference category is employed (0)

gen labourstatus1 = .	// unemployed (1) compared to employed (0)
replace labourstatus1 = 1 if labourstatus==1
replace labourstatus1 = 0 if labourstatus==0

gen labourstatus2 = .	// retired compared to employed 
replace labourstatus2 = 1 if labourstatus==2
replace labourstatus2 = 0 if labourstatus==0

gen labourstatus3 = .	// student compared to employed 
replace labourstatus3 = 1 if labourstatus==3
replace labourstatus3 = 0 if labourstatus==0

gen labourstatus4 = .	// disabled compared to employed 
replace labourstatus4 = 1 if labourstatus==4
replace labourstatus4 = 0 if labourstatus==0

gen labourstatus5 = .	// others compared to employed 
replace labourstatus5 = 1 if labourstatus==5
replace labourstatus5 = 0 if labourstatus==0


	* URBAN RURAL 

replace IMD2007 = . if IMD2007>4
rename IMD2007 ruralurban

label define ruralurban 1"village or rural area" 2"small town or middle-sized town" 3"suburbs of large city" 4"large city"
label values ruralurban ruralurban

* reference category is village

gen ruralurban2= .	// small town compared to village 
replace ruralurban2 = 1 if ruralurban==2
replace ruralurban2 = 0 if ruralurban==1

gen ruralurban3= .	// subarbs of large city compared to village 
replace ruralurban3 = 1 if ruralurban==3
replace ruralurban3 = 0 if ruralurban==1

gen ruralurban4= .	// large city compared to village 
replace ruralurban4 = 1 if ruralurban==4
replace ruralurban4 = 0 if ruralurban==1


	*INCOME 

gen income = IMD2006
replace income = . if IMD2006>5

label define income 1"lowest quantile" 2"second quantile" 3"third quantile" 4"fourth quantile" 5"highest quantile"
label values income income

* reference category is lowest quantile 

gen income2 = .	// second quantile compared to lowest quantile 
replace income2 = 1 if income==2
replace income2 = 0 if income==1

gen income3 = .	// third quantile compared to lowest quantile 
replace income3 = 1 if income==3
replace income3 = 0 if income==1

gen income4 = .	// fourth quantile compared to lowest quantile 
replace income4 = 1 if income==4
replace income4 = 0 if income==1

gen income5 = .	// fifth quantile compared to lowest quantile 
replace income5 = 1 if income==5
replace income5 = 0 if income==1

rename IMD1006_NAM country 
rename IMD1004 election 

keep if country=="Australia" | country=="Austria" | country=="Belgium" | country=="Canada" | country=="Denmark" | country=="Finland" | country=="France" | country=="Germany" | country=="Greece" | country=="Iceland" | country=="Ireland" | country=="Italy" | country=="Japan" | country=="Netherlands" | country=="New Zealand" | country=="Norway" | country=="Portugal" | country=="Spain" | country=="Sweden" | country=="Switzerland" | country=="Great Britain" | country=="United States of America" 


*These are problematic surveys that we identified:

drop if election=="DNK_2001" | election=="FIN_2003" | election=="FRA_2002" | election=="GRC_2012" | election=="ISL_2007" | election=="ITA_2006" | election=="JPN_2004" | election=="NOR_2001" | election=="PRT_2005"
 
drop if country=="Japan"
cd "${data}/randomness"	
save "randomness.dta", replace 




*************************************************************************************

** how random is the treatment ?

*grstyle init

*grstyle set plain, horizontal grid




************ Age ******************

cd "${data}/randomness"
use "randomness.dta", clear

drop if missing(age)
drop if missing(daysafter)

encode election, gen(secim)

set more off
tempname age1

postfile `age1' str40 sample b_age se_age p_value using age.dta, replace

foreach lname of numlist 1/89 {
    local t : label (secim) `lname'
    noisily regress daysafter age if secim==`lname'

    scalar p_value = 2 * ttail(e(df_r), abs(_b[age]/_se[age]))

    * Post the LABEL (survey name), not the numeric code
    post `age1' ("`t'") (_b[age]) (_se[age]) (p_value)
}

postclose `age1'

*INCOME2 

cd "${data}/randomness"
use "randomness.dta", clear
 
   drop if missing(income2)
   drop if missing(daysafter)
   
 	encode election, gen(secim)
	
	set more off
	tempname income2 
	
	postfile `income2' str40 sample b_income2 se_income2 p_value using income2.dta, replace 	
	
	foreach lname of numlist 1(1)61{  		
	local t : label (secim) `lname'
		noisily regress daysafter income2 if secim==`lname'						
		
		scalar p_value = 2 * ttail(e(df_r), abs(_b[income2]/_se[income2]))
																			
		*eststo M_`lname': margins ,  dydx(income2) post
		post `income2' ("`t'") (_b[income2]) (_se[income2]) (p_value)		
		}
		
		
	postclose `income2'
	
	

*INCOME3

cd "${data}/randomness"
use "randomness.dta", clear
 
   drop if missing(income3)
   drop if missing(daysafter)

   encode election, gen(secim)
	
	set more off
	tempname income3 
	
	postfile `income3' str40 sample b_income3 se_income3 p_value using income3.dta, replace 	
	
	foreach lname of numlist 1(1)61{  		
	local t : label (secim) `lname'
		noisily regress daysafter income3 if secim==`lname'					
		scalar p_value = 2 * ttail(e(df_r), abs(_b[income3]/_se[income3]))
																				
		*eststo M_`lname': margins ,  dydx(income3) post
		post `income3' ("`t'") (_b[income3]) (_se[income3]) (p_value)		
		}
		
		
	postclose `income3'
	

	
*INCOME4


use "randomness.dta", clear
 
   drop if missing(income4)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname income4 
	
	postfile `income4' str40 sample b_income4 se_income4 p_value using income4.dta, replace 	
	
	foreach lname of numlist 1(1)61{  		
	local t : label (secim) `lname'
		noisily regress daysafter income4 if secim==`lname'					
		scalar p_value = 2 * ttail(e(df_r), abs(_b[income4]/_se[income4]))
																				
		*eststo M_`lname': margins ,  dydx(income4) post
		post `income4' ("`t'") (_b[income4]) (_se[income4]) (p_value) 		
		}
			
	postclose `income4'
	
	
	
	
*INCOME 5

use "randomness.dta", clear
 
   drop if missing(income5)
   drop if missing(daysafter)
   
   encode election, gen(secim)
	
	set more off
	tempname income5 
	
	postfile `income5' str40 sample b_income5 se_income5 p_value using income5.dta, replace 	
	
	foreach lname of numlist 1(1)61{  		
	local t : label (secim) `lname'
		noisily regress daysafter income5 if secim==`lname'						
		scalar p_value = 2 * ttail(e(df_r), abs(_b[income5]/_se[income5]))
																			
		*eststo M_`lname': margins ,  dydx(income5) post
		post `income5' ("`t'") (_b[income5]) (_se[income5]) (p_value)		
		}
		
		
	postclose `income5'


************* EDUCATION *************

*primary or lower secondary 

 use "randomness.dta", clear
   drop if missing(education1)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname education1 
	
	postfile `education1' str40 sample b_education1 se_education1 p_value using education1.dta, replace 	
	
	foreach lname of numlist 1(1)89{  		
	local t : label (secim) `lname'
		noisily regress daysafter education1 if secim==`lname'				
		scalar p_value = 2 * ttail(e(df_r), abs(_b[education1]/_se[education1]))
		post `education1' ("`t'") (_b[education1]) (_se[education1]) (p_value) 		
		}
		
		
	postclose `education1'
				
	
*higher secondary

 use "randomness.dta", clear
   drop if missing(education2)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname education2 
	
	postfile `education2' str40 sample b_education2 se_education2 p_value using education2.dta, replace 	
	
	foreach lname of numlist 1(1)89{  		
	local t : label (secim) `lname'
		noisily regress daysafter education2 if secim==`lname'				
		scalar p_value = 2 * ttail(e(df_r), abs(_b[education2]/_se[education2]))
																				
		*eststo M_`lname': margins ,  dydx(education2) post
		post `education2' ("`t'") (_b[education2]) (_se[education2]) (p_value)		
		}
		
		
	postclose `education2'
	
	
	* post-secondary 
	
	
 use "randomness.dta", clear
   drop if missing(education3)
   drop if missing(daysafter)
   
   bysort election: egen frequency = count(education3)
	drop if frequency<20
	encode election, gen(secim)
	
	set more off
	tempname education3 
	
	postfile `education3' str40 sample b_education3 se_education3 p_value using education3.dta, replace 	
	
	foreach lname of numlist 1(1)82{  		
	local t : label (secim) `lname'
		noisily regress daysafter education3 if secim==`lname'				
		scalar p_value = 2 * ttail(e(df_r), abs(_b[education3]/_se[education3]))
																					
		*eststo M_`lname': margins ,  dydx(education3) post
		post `education3' ("`t'")  (_b[education3]) (_se[education3]) (p_value)		
		}
		
		
	postclose `education3'
			
	
	
	
*university 

 use "randomness.dta", clear
   drop if missing(education4)
   drop if missing(daysafter)
      *bysort election: egen frequency = count(education4)

 	encode election, gen(secim)
	
	set more off
	tempname education4
	
	postfile `education4' str40 sample b_education4 se_education4 p_value using education4.dta, replace 	
	
	foreach lname of numlist 1(1)88{  		
	local t : label (secim) `lname'
		noisily regress daysafter education4 if secim==`lname'			
		scalar p_value = 2 * ttail(e(df_r), abs(_b[education4]/_se[education4]))
																					
		*eststo M_`lname': margins ,  dydx(education4) post
		post `education4' ("`t'")  (_b[education4]) (_se[education4]) (p_value) 		
		} 
		
		
	postclose `education4'
			
	
	

*unemployed

 use "randomness.dta", clear
   drop if missing(labourstatus1)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname labourstatus1
	
	postfile `labourstatus1' str40 sample b_labourstatus1 se_labourstatus1 p_value using labourstatus1.dta, replace 	
	
	foreach lname of numlist 1(1)62{  		
	local t : label (secim) `lname'
		noisily regress daysafter labourstatus1 if secim==`lname'			
		scalar p_value = 2 * ttail(e(df_r), abs(_b[labourstatus1]/_se[labourstatus1]))																				
		*eststo M_`lname': margins ,  dydx(labourstatus1) post
		post `labourstatus1' ("`t'")  (_b[labourstatus1]) (_se[labourstatus1]) (p_value) 		
		}
		
	postclose `labourstatus1'
				
	
	
	
*retired

 use "randomness.dta", clear
   drop if missing(labourstatus2)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname labourstatus2
	
	postfile `labourstatus2' str40 sample b_labourstatus2 se_labourstatus2 p_value using labourstatus2.dta, replace 	
	
	foreach lname of numlist 1(1)62{  		
	local t : label (secim) `lname'
		noisily regress daysafter labourstatus2 if secim==`lname'			
		scalar p_value = 2 * ttail(e(df_r), abs(_b[labourstatus2]/_se[labourstatus2]))																				
																						
		*eststo M_`lname': margins ,  dydx(labourstatus2) post
		post `labourstatus2' ("`t'")  (_b[labourstatus2]) (_se[labourstatus2]) (p_value)  		
		}
		
		
	postclose `labourstatus2'
	
	
 * student


 use "randomness.dta", clear
   drop if missing(labourstatus3)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname labourstatus3
	
	postfile `labourstatus3' str40 sample b_labourstatus3 se_labourstatus3 p_value using labourstatus3.dta, replace 	
	
	foreach lname of numlist 1(1)62{  		
	local t : label (secim) `lname'
		noisily regress daysafter labourstatus3 if secim==`lname'			
		scalar p_value = 2 * ttail(e(df_r), abs(_b[labourstatus3]/_se[labourstatus3]))																				
																						
		*eststo M_`lname': margins ,  dydx(labourstatus3) post
		post `labourstatus3' ("`t'")  (_b[labourstatus3]) (_se[labourstatus3]) (p_value) 		
		}
		
		
	postclose `labourstatus3'
			
		
	

	
	
	
	
* disabled

 use "randomness.dta", clear
   drop if missing(labourstatus4)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname labourstatus4
	
	postfile `labourstatus4' str40 sample b_labourstatus4 se_labourstatus4 p_value using labourstatus4.dta, replace 	
	
	foreach lname of numlist 1(1)62{  		
	local t : label (secim) `lname'
		noisily regress daysafter labourstatus4 if secim==`lname'				
		scalar p_value = 2 * ttail(e(df_r), abs(_b[labourstatus4]/_se[labourstatus4]))																				
																					
		*eststo M_`lname': margins ,  dydx(labourstatus4) post
		post `labourstatus4' ("`t'")  (_b[labourstatus4]) (_se[labourstatus4]) (p_value)  		
		}
		
		
	postclose `labourstatus4'
	
	
	


* others (labour status)

 use "randomness.dta", clear
   drop if missing(labourstatus5)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname labourstatus5
	
	postfile `labourstatus5' str40 sample b_labourstatus5 se_labourstatus5 p_value using labourstatus5.dta, replace 	
	
	foreach lname of numlist 1(1)62{  		
	local t : label (secim) `lname'
		noisily regress daysafter labourstatus5 if secim==`lname'				
		scalar p_value = 2 * ttail(e(df_r), abs(_b[labourstatus5]/_se[labourstatus5]))																				
																					
		*eststo M_`lname': margins ,  dydx(labourstatus5) post
		post `labourstatus5' ("`t'")  (_b[labourstatus5]) (_se[labourstatus5]) (p_value) 		
		}
		
		
	postclose `labourstatus5'
				


* small town


 use "randomness.dta", clear
   drop if missing(ruralurban2)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname ruralurban2
	
	postfile `ruralurban2' str40 sample b_ruralurban2 se_ruralurban2 p_value using ruralurban2.dta, replace 	
	
	foreach lname of numlist 1(1)76{  		
	local t : label (secim) `lname'
		noisily regress daysafter ruralurban2 if secim==`lname'
		scalar p_value = 2 * ttail(e(df_r), abs(_b[ruralurban2]/_se[ruralurban2]))	
		*eststo M_`lname': margins ,  dydx(ruralurban2) post
		post `ruralurban2' ("`t'")  (_b[ruralurban2]) (_se[ruralurban2]) (p_value)		
		}
		
		
	postclose `ruralurban2'	
	
	

* suburbs of large city


 use "randomness.dta", clear
   drop if missing(ruralurban3)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname ruralurban3
	
	postfile `ruralurban3' str40 sample b_ruralurban3 se_ruralurban3 p_value using ruralurban3.dta, replace 	
	
	foreach lname of numlist 1(1)75{  		
	local t : label (secim) `lname'
		noisily regress daysafter ruralurban3 if secim==`lname'				
		scalar p_value = 2 * ttail(e(df_r), abs(_b[ruralurban3]/_se[ruralurban3]))	
		*eststo M_`lname': margins ,  dydx(ruralurban3) post
		post `ruralurban3' ("`t'")  (_b[ruralurban3]) (_se[ruralurban3]) (p_value)		
		}
			
	postclose `ruralurban3'	
	
	
	
	
* large city

 use "randomness.dta", clear
   drop if missing(ruralurban4)
   drop if missing(daysafter)
 	encode election, gen(secim)
	
	set more off
	tempname ruralurban4
	
	postfile `ruralurban4' str40 sample b_ruralurban4 se_ruralurban4 p_value using ruralurban4.dta, replace 	
	
	foreach lname of numlist 1(1)76{  		
	local t : label (secim) `lname'
		noisily regress daysafter ruralurban4 if secim==`lname'
		scalar p_value = 2 * ttail(e(df_r), abs(_b[ruralurban4]/_se[ruralurban4]))
		*eststo M_`lname': margins ,  dydx(ruralurban4) post
		post `ruralurban4' ("`t'")  (_b[ruralurban4]) (_se[ruralurban4]) (p_value)		
		}
		
		
	postclose `ruralurban4'
			
	
	
	
use "age.dta", clear 
gen variable =1
rename b_age b_coefficient 
rename se_age se_coefficient
save "age.dta", replace
	
use "education1.dta", clear 
gen variable = 2
rename b_education1 b_coefficient 
rename se_education1 se_coefficient
save "education1.dta", replace

use "education2", clear 
rename b_education2 b_coefficient 
rename se_education2 se_coefficient
gen variable = 3	
save "education2.dta", replace

use "education3", clear 
rename b_education3 b_coefficient 
rename se_education3 se_coefficient
gen variable = 4
save "education3.dta", replace

use "education4", clear 
rename b_education4 b_coefficient 
rename se_education4 se_coefficient
gen variable = 5
save "education4.dta", replace

use "income2", clear 
rename b_income2 b_coefficient 
rename se_income2 se_coefficient
gen variable = 6	
save "income2.dta", replace

use "income3", clear 
rename b_income3 b_coefficient 
rename se_income3 se_coefficient
gen variable = 7	
save "income3.dta", replace
	
use "income4", clear 
rename b_income4 b_coefficient 
rename se_income4 se_coefficient
gen variable = 8
save "income4.dta", replace

use "income5", clear 
rename b_income5 b_coefficient 
rename se_income5 se_coefficient
gen variable = 9
save "income5.dta", replace

use "labourstatus1", clear 
rename b_labourstatus1 b_coefficient 
rename se_labourstatus1 se_coefficient
gen variable = 10	
save "labourstatus1.dta", replace
	
use "labourstatus2", clear 
rename b_labourstatus2 b_coefficient 
rename se_labourstatus2 se_coefficient
gen variable = 11
save "labourstatus2.dta", replace

use "labourstatus3", clear 
rename b_labourstatus3 b_coefficient 
rename se_labourstatus3 se_coefficient
gen variable = 12
save "labourstatus3.dta", replace

use "labourstatus4", clear 
rename b_labourstatus4 b_coefficient 
rename se_labourstatus4 se_coefficient
gen variable = 13
save "labourstatus4.dta", replace

use "labourstatus5", clear 
rename b_labourstatus5 b_coefficient 
rename se_labourstatus5 se_coefficient
gen variable = 14
save "labourstatus5.dta", replace

use "ruralurban2", clear 
rename b_ruralurban2 b_coefficient 
rename se_ruralurban2 se_coefficient
gen variable = 15
save "ruralurban2.dta", replace

use "ruralurban3", clear 
rename b_ruralurban3 b_coefficient 
rename se_ruralurban3 se_coefficient
gen variable = 16
save "ruralurban3.dta", replace

use "ruralurban4", clear 
rename b_ruralurban4 b_coefficient 
rename se_ruralurban4 se_coefficient
gen variable = 17
save "ruralurban4.dta", replace

use "age.dta", clear 
append using "education1.dta"  "education2.dta" "education3.dta"  "education4.dta" "income2.dta" "income3.dta"  "income4.dta" "income5.dta" "labourstatus1.dta" "labourstatus2.dta" "labourstatus3.dta" "labourstatus4.dta" "labourstatus5.dta" "ruralurban2.dta" "ruralurban3.dta"  "ruralurban4.dta"

label define variablelabels 1"age" 2"primary or lower secondary" 3"higher secondary" 4"post-secondary" 5"university" 6"second quantile" 7"third quantile" 8"fourth quantile" 9"fifth quantile" 10"unemployed" 11 "retired" 12 "student" 13 "disabled" 14"others" 15 "small town" 16 "subarbs of large city" 17 "large city"
				
label values  variable variablelabels
drop if p_value==.
gen significant = 0
replace significant = 1 if p_value<0.05


save "merged.dta", replace 

cd "${data}/randomness"	
use "merged.dta", clear 

dotplot p_value, over(variable) center xlabel(, angle(90) labsize(small)) xtitle("") yscale(range(0(0.2)1)) ylabel(0(0.2)1) yline(0.01, lpattern(dash) lcolor(black)) msize(1.5pt) jitter(3.5) ysize(6) xsize(8) colorvar(significant) colorrule(%25) colordiscrete coloruseplegend colorlist(gs12%50 black%70) 

 graph save "${figures}/figureH2.gph",  replace
 graph export "${figures}/figureH2.png",  replace
 
 
 dotplot b_coefficient, over(variable) center xlabel(, angle(90) labsize(small)) xtitle("") yscale(range(-40(10)40)) ylabel(-40(10)40) yline(0.01, lpattern(dash) lcolor(black)) msize(1.5pt) jitter(3.5) ysize(6) xsize(8) colorvar(significant) colorrule(%25) colordiscrete coloruseplegend colorlist(gs12%50 black%70) 

 graph save "${figures}/figureH3.gph",  replace
 graph export "${figures}/figureH3.png",  replace
 
 
*keep if significant ==1 

*dotplot b_coefficient, over(variable) center xlabel(, angle(90) labsize(small)) xtitle("") msize(3pt) jitter(3.5)  yline(0, lpattern(dash) lcolor(black)) 


 
 
 

